var mainTabs;
Ext.onReady(function() {
        Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
        Ext.QuickTips.init();
        var themeMenu = new Ext.menu.Menu({
				id : 'themeMenu',
				items : [{
							text : '皮肤设置',
							iconCls : 'bugIcon',
							handler : function() {
								//themeWindowInit();
							}
						}, {
							text : '布局设置',
							iconCls : 'layoutIcon',
							handler : function() {
								//layoutWindowInit();
							}
						}]
			});
			
		var themeButton = new Ext.Button({
					text : '主题',
					iconCls : 'themeIcon',
					iconAlign : 'left',
					scale : 'medium',
					width : 50,
					tooltip : '<span style="font-size:12px">切换系统主题样式</span>',
					pressed : false,
					arrowAlign : 'right',
					renderTo : 'themeDiv',
					menu: themeMenu
				});
	
		var mainMenu = new Ext.menu.Menu({
					id : 'mainMenu',
					items : [{
								text : '密码修改',
								iconCls : 'keyIcon',
								handler : function() {
									//updateUserInit();
								}
							}, {
								text : '系统锁定',
								iconCls : 'lockIcon',
								handler : function() {
									//lockWindow.show();
									//setCookie("g4.lockflag", '1', 240);
								}
							}]
				});
	
		var configButton = new Ext.Button({
					text : '首选项',
					iconCls : 'config2Icon',
					iconAlign : 'left',
					scale : 'medium',
					width : 50,
					tooltip : '<span style="font-size:12px">首选项设置</span>',
					pressed : false,
					renderTo : 'configDiv',
					menu : mainMenu
				});
	
		var closeButton = new Ext.Button({
					iconCls : 'cancel_25Icon',
					iconAlign : 'left',
					scale : 'medium',
					width : 30,
					tooltip : '<span style="font-size:12px">切换用户,安全退出系统</span>',
					pressed : false,
					arrowAlign : 'right',
					renderTo : 'closeDiv',
					handler : function() {
						//logout();
					}
				});
		
	/**
		生成菜单，需为动态
	*/		
	var node_0101 = new Ext.tree.TreeNode({
		text:'系统管理',
		listeners: {
          'click': function(){
		   }},
		expanded:false,
		iconCls:'folder_wrenchIcon',
		id:'id_node_0101'
	});
	var node_010102 = new Ext.tree.TreeNode({
		text:'权限管理',
		listeners: {
          'click': function(){
		   }},
		expanded:true,
		id:'id_node_010102'
	});
	var node_01010201 = new Ext.tree.TreeNode({
		text:'组织机构管理',
		listeners: {
          'click': function(){
             addTab('orgnization!init.action','组织机构管理','01010201','G4Stuido开发平台 -> 系统管理 -> 权限管理 -> 组织机构管理','chart_organisation.png');
		   }},
		expanded:false,
		iconCls:'chart_organisationIcon',
		id:'id_node_01010201'
	});
	var node_01010301 = new Ext.tree.TreeNode({
		text:'字典维护',
		listeners: {
          'click': function(){
             addTab('resource.action?reqCode=codeTableInit','字典维护','01010301','G4Stuido开发平台 -> 系统管理 -> 基础数据维护 -> 字典维护','application_view_list.png');
		   }},
		expanded:false,
		iconCls:'application_view_listIcon',
		id:'id_node_01010301'
	});
	var node_01010403 = new Ext.tree.TreeNode({
		text:'Requst请求跟踪',
		listeners: {
          'click': function(){
             addTab('eventTrack.action?reqCode=init','Requst请求跟踪','01010403','G4Stuido开发平台 -> 系统管理 -> 运行监控 -> Requst请求跟踪','bug.png');
		   }},
		expanded:false,
		iconCls:'bugIcon',
		id:'id_node_01010403'
	});

	var node_01010204 = new Ext.tree.TreeNode({
		text:'角色管理与授权',
		listeners: {
          'click': function(){
             addTab('role.action?reqCode=roleInit','角色管理与授权','01010204','G4Stuido开发平台 -> 系统管理 -> 权限管理 -> 角色管理与授权','award_star_silver_3.png');
		   }},
		expanded:false,
		iconCls:'award_star_silver_3Icon',
		id:'id_node_01010204'
	});
	var node_010103 = new Ext.tree.TreeNode({
		text:'基础数据维护',
		listeners: {
          'click': function(){
		   }},
		expanded:true,
		id:'id_node_010103'
	});
	var node_01010303 = new Ext.tree.TreeNode({
		text:'全局参数表维护',
		listeners: {
          'click': function(){
             addTab('param.action?reqCode=init','全局参数表维护','01010303','G4Stuido开发平台 -> 系统管理 -> 基础数据维护 -> 全局参数表维护','config.png');
		   }},
		expanded:false,
		iconCls:'configIcon',
		id:'id_node_01010303'
	});
	var node_01010401 = new Ext.tree.TreeNode({
		text:'Session会话监控',
		listeners: {
          'click': function(){
             addTab('sessionMonitor.action?reqCode=init','Session会话监控','01010401','G4Stuido开发平台 -> 系统管理 -> 运行监控 -> Session会话监控','user_comment.png');
		   }},
		expanded:false,
		iconCls:'user_commentIcon',
		id:'id_node_01010401'
	});

	var node_01010202 = new Ext.tree.TreeNode({
		text:'人员管理与授权',
		listeners: {
          'click': function(){
             addTab('user.action?reqCode=userInit','人员管理与授权','01010202','G4Stuido开发平台 -> 系统管理 -> 权限管理 -> 人员管理与授权','group_link.png');
		   }},
		expanded:false,
		iconCls:'group_linkIcon',
		id:'id_node_01010202'
	});

	var node_010104 = new Ext.tree.TreeNode({
		text:'运行监控',
		listeners: {
          'click': function(){
		   }},
		expanded:true,
		id:'id_node_010104'
	});
	var node_01010405 = new Ext.tree.TreeNode({
		text:'JDBC执行监控',
		listeners: {
          'click': function(){
             addTab('jdbcMonitor.action?reqCode=jdbcInit','JDBC执行监控','01010405','G4Stuido开发平台 -> 系统管理 -> 运行监控 -> JDBC执行监控','database_refresh.png');
		   }},
		expanded:false,
		iconCls:'database_refreshIcon',
		id:'id_node_01010405'
	});

	var node_01010205 = new Ext.tree.TreeNode({
		text:'菜单资源管理',
		listeners: {
          'click': function(){
             addTab('resource.action?reqCode=menuResourceInit','菜单资源管理','01010205','G4Stuido开发平台 -> 系统管理 -> 权限管理 -> 菜单资源管理','arrow_switch.png');
		   }},
		expanded:false,
		iconCls:'arrow_switchIcon',
		id:'id_node_01010205'
	});

	var node_01010406 = new Ext.tree.TreeNode({
		text:'系统异常监控',
		listeners: {
          'click': function(){
             addTab('beanMonitor.action?reqCode=init','系统异常监控','01010406','G4Stuido开发平台 -> 系统管理 -> 运行监控 -> 系统异常监控','disconnect.png');
		   }},
		expanded:false,
		iconCls:'disconnectIcon',
		id:'id_node_01010406'
	});

	var node_01010206 = new Ext.tree.TreeNode({
		text:'UI元素托管',
		listeners: {
          'click': function(){
             addTab('part.action?reqCode=init','UI元素托管','01010206','G4Stuido开发平台 -> 系统管理 -> 权限管理 -> UI元素托管','app_boxes.png');
		   }},
		expanded:false,
		iconCls:'app_boxesIcon',
		id:'id_node_01010206'
	});

	var node_01010407 = new Ext.tree.TreeNode({
		text:'服务器信息',
		listeners: {
          'click': function(){
             addTab('serverInfo.action?reqCode=init','服务器信息','01010407','G4Stuido开发平台 -> 系统管理 -> 运行监控 -> 服务器信息','server_connect.png');
		   }},
		expanded:false,
		iconCls:'server_connectIcon',
		id:'id_node_01010407'
	});

	var node_01010207 = new Ext.tree.TreeNode({
		text:'UI元素角色授权',
		listeners: {
          'click': function(){
             addTab('rolePart.action?reqCode=init','UI元素角色授权','01010207','G4Stuido开发平台 -> 系统管理 -> 权限管理 -> UI元素角色授权','app_left.png');
		   }},
		expanded:false,
		iconCls:'app_leftIcon',
		id:'id_node_01010207'
	});

	var node_01010208 = new Ext.tree.TreeNode({
		text:'UI元素人员授权',
		listeners: {
          'click': function(){
             addTab('userPart.action?reqCode=init','UI元素人员授权','01010208','G4Stuido开发平台 -> 系统管理 -> 权限管理 -> UI元素人员授权','app_right.png');
		   }},
		expanded:false,
		iconCls:'app_rightIcon',
		id:'id_node_01010208'
	});

	node_0101.appendChild(node_010102);

	node_010102.appendChild(node_01010201);

	node_010103.appendChild(node_01010301);

	node_010104.appendChild(node_01010403);

	node_010102.appendChild(node_01010204);

	node_0101.appendChild(node_010103);

	node_010103.appendChild(node_01010303);

	node_010104.appendChild(node_01010401);

	node_010102.appendChild(node_01010202);

	node_0101.appendChild(node_010104);

	node_010104.appendChild(node_01010405);

	node_010102.appendChild(node_01010205);

	node_010104.appendChild(node_01010406);

	node_010102.appendChild(node_01010206);

	node_010104.appendChild(node_01010407);

	node_010102.appendChild(node_01010207);

	node_010102.appendChild(node_01010208);

	var treePanel_0101 = new Ext.tree.TreePanel({
       autoHeight:false,
       autoWidth:false,
       autoScroll:false,
       animate:false,
       rootVisible:false,
       useArrows:true,
       title:'',
       border: false,
       containerScroll:true,
       applyTo:'div.card.0101',
	   root:node_0101
	});
	/////////////////////////////////////////////////////////////////////////////////////////////
	/**
		功能tab页
	*/
	 mainTabs = new Ext.TabPanel({
                region: 'center', 
                deferredRender: false,
                activeTab: 0,
                enableTabScroll:true,
                frame:true,
                plugins: new Ext.ux.TabCloseMenu(),
                items: [{
                    contentEl: 'center1',
                    title: '我的桌面',
                    closable: false,
                    autoScroll: true
                }]
            });
    
        var viewport = new Ext.Viewport({
            layout: 'border',
            items: [
             {
                region: 'north',
                split: false,
                title:APPTITLE,
                height: 85, 
                border:false,
                collapsible: false,
                //html:"<img src='resource/images/title_banner.gif'></img>",
                contentEl:"north",
                frame:false,
                margins: '0 0 0 0'
            },{
                region: 'south',
                contentEl: 'south',
                split: true,
                height: 17,
                collapsible: false,
                margins: '0 0 0 0'
            }, {
                region: 'west',
                id: 'menu-panel',
                title: '系统菜单',
                split: true,
                width: 200,
                minSize: 175,
                maxSize: 400,
                collapsible: true,
                margins: '0 0 0 5',
                layout: {
                    type: 'accordion',
                    animate: true
                },
                items: [{
                    title: '系统管理',
                    contentEl: 'div.card.0101',
                    border: false,
                    iconCls: 'configIcon'
                },{
                    contentEl: 'west',
                    title: '测试功能',
                    border: false,
                    iconCls: 'nav'
                }]
            },mainTabs
           ]
        });
});

/**

 * 响应树节点单击事件

 */

function addTab(url,name,menuid,pathCh,icon){
  if(Ext.isEmpty(icon)){
    icon = 's.gif';
  }
  var id = "tab_id_" + menuid;
  if(url == '#' || url == ''){
	return;
  }else{
	var index = url.indexOf('.action');
	if(index != -1){
	  url = url + '?menuid4Log=' + menuid;
	}
	var n = mainTabs.getComponent(id);
	if (!n) {
	   n = mainTabs.add({
	     id:id,
	     title:"<img align='top' class='IEPNG' src='resource/images/icons/menus/" + icon + "'/>" + name,
	     closable:true,
	     layout:'fit',
	     //listeners: {activate: function(){Ext.getCmp('centerPanel').setTitle(pathCh)}},
	     html:'<iframe scrolling="auto" frameborder="0" width="100%" height="100%" src='+url+'></iframe>'
	  });
	}
	mainTabs.setActiveTab(n);
 }
}

